/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.graphs3d;

import java.awt.Color;
import javax.media.j3d.Appearance;
import javax.media.j3d.Geometry;
import javax.media.j3d.LineArray;
import javax.media.j3d.LineAttributes;
import javax.media.j3d.Shape3D;
import javax.vecmath.Color3f;
import javax.vecmath.Point3f;

/**
 *
 * @author Elad
 */
public class Positive2DAxises extends Shape3D {

    public Positive2DAxises() {
        LineAttributes la = new LineAttributes();
        la.setLineWidth(2);
        Appearance app = new Appearance();
        app.setLineAttributes(la);
        this.setAppearance(app);
        this.setGeometry(createGeometry());
    }

    private Geometry createGeometry() {
        final Color3f blue = new Color3f(new Color(3, 141, 187));
        final Color3f red = new Color3f(new Color(167, 66, 91));

        //mark scale parameters:
        float interval = 0.1f;
        float scaleLength = 0.02f;
        int numOfScales = (int) (1.0 / interval);

        // create line for Y axis
        LineArray axisLines = new LineArray(4 + numOfScales * 4,
                LineArray.COORDINATES | LineArray.COLOR_3);

        axisLines.setCoordinate(0, new Point3f(0.0f, 0.0f, 0.0f));
        axisLines.setCoordinate(1, new Point3f(0.0f, 1.0f, 0.0f));
        axisLines.setCoordinate(2, new Point3f(0.0f, 0.0f, 0.0f));
        axisLines.setCoordinate(3, new Point3f(1.0f, 0.0f, 0.0f));
        //axisLines.setCoordinate(4, new Point3f(0.0f, 0.0f, 0.0f));
        //axisLines.setCoordinate(5, new Point3f(0.0f, 0.0f, 1.0f));

        //adding scale marks:
        for (int i = 0; i < numOfScales; i++) {
            //           System.out.println(i+"interval*(i+1)"+interval*(i+1));
            axisLines.setCoordinate(0 + i * 4 + 4, new Point3f(0.0f, interval * (i + 1), 0.0f));
            axisLines.setCoordinate(1 + i * 4 + 4, new Point3f(scaleLength, interval * (i + 1), 0.0f));
       //     axisLines.setCoordinate(2 + i * 8 + 4, new Point3f(0.0f, interval * (i + 1), 0.0f));
       //     axisLines.setCoordinate(3 + i * 8 + 4, new Point3f(0.0f, interval * (i + 1), scaleLength));
       //     axisLines.setCoordinate(4 + i * 8 + 4, new Point3f(interval * (i + 1), 0.0f, 0.0f));
       //     axisLines.setCoordinate(5 + i * 8 + 4, new Point3f(interval * (i + 1), 0.0f, scaleLength));
            axisLines.setCoordinate(2 + i * 4 + 4, new Point3f(interval * (i + 1), 0.0f, 0.0f));
            axisLines.setCoordinate(3 + i * 4 + 4, new Point3f(interval * (i + 1), scaleLength, 0.0f));
        /*axisLines.setCoordinate(8 + i * 12 + 4, new Point3f(0.0f, 0.0f, interval * (i + 1)));
        axisLines.setCoordinate(9 + i * 12 + 4, new Point3f(scaleLength, 0.0f, interval * (i + 1)));
        axisLines.setCoordinate(10 + i * 12 + 4, new Point3f(0.0f, 0.0f, interval * (i + 1)));
        axisLines.setCoordinate(11 + i * 12 + 4, new Point3f(0.0f, scaleLength, interval * (i + 1)));*/
        }

        for (int i = 0; i < 4; i++) {
            axisLines.setColor(i, blue);
        }
        for (int i = 4; i < 4 + numOfScales * 4; i++) {
            axisLines.setColor(i, red);
        }
        /*axisLines.setColor(0, blue);
        axisLines.setColor(1, red);
        axisLines.setColor(2, blue);
        axisLines.setColor(3, red);
        axisLines.setColor(4, blue);
        axisLines.setColor(5, red);*/

        return axisLines;
    }
}
